package testing;

import static org.junit.Assert.*;

import org.junit.Test;

import hypeerweb.HyPeerWeb;
import hypeerweb.Node;
import hypeerweb.SimplifiedNodeDomain;
import testing.hypeerweb.ExpectedResult;

/*
 * Create JUnit test cases for some class of your choosing. 
 * Perform 4 forms of whitebox testing: loop testing, relational 
 * testing, internal boundary value testing, and dataflow testing.
 *  Also, you are to provide a code coverage report showing 100% (or as close as possible) 
 *  code coverage on the methods tested. You only need test enough methods 
 *  to demonstrate the four forms of whitebox testing. Your JUnit test cases
 *   should be well documented for it is the documentation I will grade.

Grading Criteria
 */

public class BrentTests {
	public static HyPeerWeb hp = null;
	@Test
	public void test() {
		hp = HyPeerWeb.getSingleton();
		loopTest();
		relationalTest();
		internalBoundaryTest();
		dataFlowTest();
	}
	
	private void loopTest() {
		hp.clear();
		Node node0 = new Node(0);
		assertTrue(node0.getHeight() == 0);
		
		Node node1 = new Node(1);
//		hp.addNode(node0);
		hp.addToHyPeerWeb(node1, node0);
		assertTrue(node1.getHeight() == 1);
		assertTrue(node0.getHeight() == 1);
	}
	
	private void relationalTest() {
		hp.clear();
		Node node0 = new Node(0);
		assertTrue(node0.getHeight() == 0);
		
		Node node1 = new Node(1);
//		hp.addNode(node0);
		hp.addToHyPeerWeb(node1, node0);
		assertTrue(node1.getHeight() == 1);
		assertTrue(node0.getHeight() == 1);
	}
	
	private void internalBoundaryTest() {

		hp.clear();
		Node node0 = new Node(0);
		Node node1 = new Node(1);
		Node node2 = new Node(2);
		hp.addToHyPeerWeb(node0, null);
		assertTrue(hp.contains(node0));
		assertFalse(hp.contains(node1));
		assertFalse(hp.contains(node2));
		
		hp.addToHyPeerWeb(node1, node0);
		assertTrue(hp.contains(node0));
		assertTrue(hp.contains(node1));
		assertFalse(hp.contains(node2));
		
		hp.addToHyPeerWeb(node2, node1);
		assertTrue(hp.contains(node0));
		assertTrue(hp.contains(node1));
		assertTrue(hp.contains(node2));
	}
	
	private void dataFlowTest() {
		hp.clear();
		Node node0 = new Node(0);
		hp.addToHyPeerWeb(node0, null);

		for (int i = 1; i < 32; i++) {
			Node node = new Node(i);
			node0.addToHyPeerWeb(node);
			ExpectedResult expectedResult = new ExpectedResult(i + 1, 0);
			assertTrue(node0.constructSimplifiedNodeDomain().equals(expectedResult));
		}
	}
}
